const btnEle = document.querySelector('.toggle')
const hourEle = document.querySelector('.hour')
const minuteEle = document.querySelector('.minute')
const secondEle = document.querySelector('.second')
const timeEle = document.querySelector('.time')
const dateEle = document.querySelector('.date')

const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

btnEle.addEventListener('click', (e) => {
    const html = document.querySelector('html')
    html.classList.toggle('dark')
    if (html.classList.contains('dark')) {
        e.target.value = 'Light Node'
    } else {
        e.target.value = 'Dark Node'
    }

})
function setTime() {
    const time = new Date()
    const month = time.getMonth()
    const day = time.getDay()
    const date = time.getDate()
    const hours = time.getHours()
    const hoursForClock = hours > 12 ? hours % 12 : hours
    const minutes = time.getMinutes()
    const seconds = time.getSeconds()
    const ampm = hours > 12 ? 'PM' : 'AM'

    hourEle.style.transform = `translate(-50%, -100%) rotate(${scale(hoursForClock, 0 ,12, 0, 360)}deg)`
    minuteEle.style.transform = `translate(-50%, -100%) rotate(${scale(minutes, 0 ,60, 0, 360)}deg)`
    secondEle.style.transform = `translate(-50%, -100%) rotate(${scale(seconds, 0 ,60, 0, 360)}deg)`

    timeEle.innerText = `${hoursForClock}:${minutes < 10 ? '0' + minutes : minutes} ${ampm}`
    dateEle.innerHTML = `${days[day]}, ${months[month]} <span class="circle">${date}</span>`
}
const scale = (num, in_min, in_max, out_min, out_max) => {
    return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

setTime()
setInterval(setTime, 1000)

